<template>
  <div>

      <van-nav-bar
          title="中国人民公安大学图书馆选座"/>
      <van-cell-group title="个人信息">
        <van-cell   @click="userDetailsClick(user)" title="用户："  :value='user.name'  is-link/>
        <van-cell title="学号/工号：" :value="user.number"/>
      </van-cell-group>
      <van-cell-group title="选座记录" >

        <van-cell  @click="seatSelectionDetailsClick(index)" v-for="index in seatSelectionDetails" :key="index.id" value="详情"  is-link :label="index.start" >
          <template #title>
            <span class="custom-title">{{ index.libraryName+"-"+index.floorNumber+"楼" }}</span>
            <span style="padding: 5px"></span>
            <van-tag v-if="index.end.substr(11,8)!=='22:00:00'" type="success">已退座</van-tag>
            <van-tag v-else type="warning">未退座</van-tag>
          </template>
          <div style="padding: 8px"></div>
        </van-cell>

      </van-cell-group>
      <div style="height: 50px"></div>
      <Tabbar></Tabbar>

  </div>

</template>

<script>
import {listSeatSelectionDetails} from "@/api/seat-selection";
import {getCurrentUser} from '@/api/user'
import Tabbar from "@/components/Tabbar";

export default {
  components: {Tabbar},
  created(){
    getCurrentUser()
        .then(response=>{
          if(response.data.code===401)
            this.$router.push("login")
          this.user = response.data;
        }
    )
    listSeatSelectionDetails(this.seatSelectionDetailsParam).then(response=>{
      this.seatSelectionDetails = response.data;
    })
  },
  name: "User",
  data(){
    return{
      user:{
        id: 0,
        name: "",
        number: "",
        phone: "",
        sex: "",
        type: 0,
      },
      seatSelectionDetailsParam:{
        seatSelectionId:null,
        userId:null
      },
      seatSelectionDetails:[{
        end: "",
        floorNumber: "",
        id:0,
        libraryName: "",
        number: "",
        start: "",
      }]
    }
  },
  methods:{
    userDetailsClick(index){
      this.$router.push({name:'userDetails',params:index})
    },
    seatSelectionDetailsClick(user){
      this.$router.push({
        name:'seatSelectionDetails',params:user
      })

    }
  }
}
</script>


<style scoped>

</style>
